package component;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import pojo.User;

/**
 * @author: ZhouBert
 * @date: 2020/9/16
 * @description: 	测试在 FactoryBean 中修改 b.d.
 * (其实只要能够继承 ApplicationContextAware + 在创建bean 方法中调用对应的方法即可！)
 */
public class MyFactoryBeanTestCache implements FactoryBean<User>, ApplicationContextAware {

	private AnnotationConfigApplicationContext context;

	@Override
	public User getObject() throws Exception {
		System.out.println("context = " + context);
		/// 成功删除 b.d.
		//context.removeBeanDefinition("mytest");
		return new User();
	}

	@Override
	public Class<?> getObjectType() {
		return User.class;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		context = (AnnotationConfigApplicationContext) applicationContext;
	}
}
